package com.aaie.gru.response;

import lombok.Data;

/**
 * 响应格式
 * @param <M>
 */
@Data
public class ResponseVO<M> {

    // 【0：成功，1：业务异常，999：系统异常】
    private int code;
    private String message;
    private M data;

    public ResponseVO() {
    }

    /**
     * 成功
     * @param m
     * @param <M>
     * @return
     */
    public static <M> ResponseVO success(M m) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setCode(0);
        responseVO.setMessage("success");
        responseVO.setData(m);
        return responseVO;
    }

    /**
     * 业务异常
     * @param message
     * @param <M>
     * @return
     */
    public static <M> ResponseVO serviceError(String message) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setCode(1);
        responseVO.setMessage(message);
        return responseVO;
    }

    /**
     * 系统异常
     * @param message
     * @param <M>
     * @return
     */
    public static <M> ResponseVO appError(String message) {
        ResponseVO responseVO = new ResponseVO();
        responseVO.setCode(999);
        responseVO.setMessage(message);
        return responseVO;
    }
}
